home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / COSH.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  54 lines

  1. /* 1.0  05-16-84 */
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************
  7.  *    Programmmed using the algorithms given in:
  8.  *
  9.  *    Coty, William J., Jr., and Waite, William, SOFTWARE MANUAL FOR
  10.  *    THE ELEMENTARY FUNCTIONS, Prentice-Hall Series in Computational
  11.  *    Mathematics, Prentice-Hall, Inc., Inglewood Cliffs, NJ, 1980,
  12.  *    pp. 217-238.
  13.  *
  14.  *----------------------------------------------------------------------*/
  15.  
  16. #include "defs.h"
  17. #include "stdtyp.h"
  18. #include "errno.h"
  19. #include "mathtyp.h"
  20. #include "mathcons.h"
  21.  
  22. /*----------------------------------------------------------------------*/
  23.  
  24. #define LNv    0.69316101074218750000
  25. #define Vm2    0.24999308500451499336
  26. #define Vov2m1    0.13830277879601902638e-4
  27.  
  28. /************************************************************************/
  29.     double
  30. cosh(x)                /* return hyperbolic cosine of x    */
  31.  
  32. /*----------------------------------------------------------------------*/
  33. double x;
  34. {
  35.     double y, w, z;
  36.     
  37.     if ((y = ABS(x)) > 1.0)
  38.     {    w = y - LNv;
  39.         if (w > LOGINFINITY)
  40.         {    errno = ERANGE;
  41.             return INFINITY;
  42.         }
  43.         z = exp(w);
  44.         if (w < PRECISION)
  45.             z += Vm2 / z;
  46.         z += Vov2m1 * z;
  47.     }
  48.     else
  49.     {    z = exp(y);
  50.         z = ldexp(z,-1) + 0.5 / z;
  51.     }
  52.     return z;
  53. }
  54.